package com.example.jjc.rxjava_retrofit2_demo;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.example.jjc.rxjava_retrofit2_demo.module.Fra_1;
import com.example.jjc.rxjava_retrofit2_demo.module.Fra_2;
import com.example.jjc.rxjava_retrofit2_demo.module.Fra_3;
import com.example.jjc.rxjava_retrofit2_demo.module.Fra_4;
import com.example.jjc.rxjava_retrofit2_demo.module.Fra_5;
import com.example.jjc.rxjava_retrofit2_demo.module.Fra_6;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.example.jjc.rxjava_retrofit2_demo.BaseFragment.FRA_TAG_1;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.toolBar)
    Toolbar toolBar;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private static MainActivity instance;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        instance = this;

        setSupportActionBar(toolBar);//actionBar设置为ToolBar
        toolBar.setTitleTextColor(Color.WHITE);

        viewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
            @Override
            public int getCount() {
                return 6;
            }

            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 0:
                        FRA_TAG_1 = "android:switcher:" + viewPager.getId() + ":" + 0;
                        return new Fra_1();
                    case 1:
                        return new Fra_2();
                    case 2:
                        return new Fra_3();
                    case 3:
                        return new Fra_4();
                    case 4:
                        return new Fra_5();
                    case 5:
                        return new Fra_6();
                    default:
                        FRA_TAG_1 = "android:switcher:" + viewPager.getId() + ":" + 0;
                        return new Fra_1();
                }
            }

            @Override
            public CharSequence getPageTitle(int position) {
                switch (position) {
                    case 0:
                        return getString(R.string.zhuangbi);
                    case 1:
                        return getString(R.string.meizhi);
                    case 2:
                        return "3";
                    case 3:
                        return "4";
                    case 4:
                        return "5";
                    case 5:
                        return "6";
                    default:
                        return getString(R.string.zhuangbi);
                }
            }
        });
        tabs.setupWithViewPager(viewPager);
        tabs.setTabTextColors(Color.GRAY,Color.WHITE);
    }

    public static MainActivity getInstance() {
        return instance;
    }
}
